import registnet.dao.RegistrarUserPeer;
import registnet.dao.RegistrarUser;
import registnet.dao.SystemLogPeer;

/* [start]	defines a renderer for the grades */
private class UserRenderer implements ListitemRenderer  {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
/* [end] */

retrieveUsers(){
	List users = new RegistrarUserPeer().getInactiveUsers();
	
	String[] listModel = new String[users.size()];
	
	for(int i=0; i<users.size(); i++){
		RegistrarUser user = users.get(i);
		listModel[i] = user.getUsername();
	}
	
	ListModel strset = new SimpleListModel(listModel);
	users_lb.setModel(strset);
	users_lb.setItemRenderer(new UserRenderer());
}

void activate(){
	RegistrarUserPeer rup = new RegistrarUserPeer();
	if(users_lb.getSelectedCount() != 0){
		int isConfirmed = Messagebox.show("Proceed?", "Activate User", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
		if (isConfirmed == Messagebox.YES){
			Iterator i = users_lb.getSelectedItems().iterator();
			while(i.hasNext()){
				Listitem listitem = i.next(); 
				RegistrarUser ru = rup.getRegistrarUser(listitem.getLabel());
				rup.activate(ru.getUserId());
				SystemLogPeer.createNewSystemLog(ru.getUsername() +" Registrar user was activated.", "registnet", "Administrator");
			}
			retrieveUsers();
		}			
	}
	else{
		alert("Select one user");
	}
}

void delete(){
	RegistrarUserPeer rup = new RegistrarUserPeer();
	if(users_lb.getSelectedCount() != 0){
		int isConfirmed = Messagebox.show("Proceed?", "Delete User", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
		if (isConfirmed == Messagebox.YES){
			Iterator i = users_lb.getSelectedItems().iterator();
			while(i.hasNext()){
				Listitem listitem = i.next();
				RegistrarUser ru = rup.getRegistrarUser(listitem.getLabel());
				rup.deleteRegistrarUser(ru.getUserId());
				SystemLogPeer.createNewSystemLog(ru.getUsername() +" Registrar user was deleted.", "registnet", "Administrator");
			}
			retrieveUsers();
		}			
	}
	else{
		alert("Select one user");
	}
}
